<template>
	<div class="login-wrap">
		<div class="ms-login">
			<div class="ms-title">后台管理</div>
			<div class="yindao_wrap">
				<el-button @click='yindaoRouter()' type="primary">引导登录</el-button>
			</div>
			<!--<el-form :model="param" :rules="rules" ref="login" label-width="0px" class="ms-content">
				<el-form-item prop="username">
					<el-input v-model="param.username" placeholder="username">
						<el-button slot="prepend" icon="el-icon-lx-people"></el-button>
					</el-input>
				</el-form-item>
				<el-form-item prop="password">
					<el-input type="password" placeholder="password" v-model="param.password" @keyup.enter.native="submitForm()">
						<el-button slot="prepend" icon="el-icon-lx-lock"></el-button>
					</el-input>
				</el-form-item>
				<div class="" style="padding-bottom: 15px;">
					<el-checkbox v-model="isRemember">记住密码</el-checkbox>
				</div>
				<div class="login-btn">
					<el-button type="primary" @click="submitForm()">登录</el-button>
				</div>
			</el-form>-->
		</div>
	</div>
</template>

<script>
	export default {
		data: function() {
			return {
				param: {
					username: '',
					password: '',
				},
				isRemember: true,
				rules: {
					username: [{
						required: true,
						message: '请输入用户名',
						trigger: 'blur'
					}],
					password: [{
						required: true,
						message: '请输入密码',
						trigger: 'blur'
					}],
				},
			};
		},
		created() {
			let musername = localStorage.getItem('musername');
			let mpassword = localStorage.getItem('mpassword');
			if(musername) {
				this.param.username = musername
			}
			if(mpassword) {
				this.param.password = mpassword
			}
		},
		methods: {
			yindaoRouter() {
				let eUrl = encodeURI('http://115.26.89.144');
				window.location.href = 'http://authserver.tmu.edu.cn/authserver/oauth2.0/authorize?response_type=code&client_id=EoCOWF80&redirect_uri='+eUrl+'&state=1'
			},
			submitForm() {
				let that = this;
				that.$router.push({
					path: '/'
				})
				return false;
				this.$refs.login.validate(valid => {
					if(valid) {
						that.param.username = that.param.username.trim();
						that.param.password = that.param.password.trim();

						that.postAxios("/Web/Login", {
							UserName: that.param.username,
							PassWord: that.param.password, //syjones
						}).then((res) => {
							if(res.code == 0) {
								//是否保存密码
								if(that.isRemember) {
									localStorage.setItem("musername", that.param.username);
									localStorage.setItem("mpassword", that.param.password);
								}
								localStorage.setItem("dept", res.data.dept);
								localStorage.setItem("limit", res.data.limit);
								localStorage.setItem("username", res.data.username);
								localStorage.setItem("userId", res.data.id);
								let urlParam = this.getQueryVariable('redirect');
								if(urlParam) {
									urlParam = unescape(urlParam);
								} else {
									urlParam = '/'
								}
								console.log('urlParam', urlParam)
								that.$message({
									message: '登录成功',
									type: 'success',
									duration: 1000,
									onClose: function() {
										that.$router.push({
											path: urlParam
										})
									}
								})

							} else {
								that.$message({
									message: res.msg,
									type: 'error',
									duration: 1000,
								})
							}
						})
					} else {
						this.$message.error('请输入账号和密码');
						console.log('error submit!!');
						return false;
					}
				});
			},
			//获取url参数
			getQueryVariable(variable) {
				var query = window.location.search.substring(1);
				var vars = query.split("&");
				for(var i in vars) {
					var pair = vars[i].split("=");
					if(pair[0] == variable) {
						return pair[1];
					}
				}
				return(false);
			},
		},
	};
</script>

<style scoped lang="scss">
	.login-wrap {
		position: relative;
		width: 100%;
		height: 100%;
		/*background-image: url(../../assets/img/login-bg.jpg);*/
		/*background-size: 100%;*/
	}
	
	.ms-title {
		width: 100%;
		line-height: 50px;
		text-align: center;
		font-size: 20px;
		color: #3395f9;
		border-bottom: 1px solid #ddd;
	}
	
	.ms-login {
		position: absolute;
		left: 50%;
		top: 50%;
		width: 350px;
		margin: -190px 0 0 -175px;
		border-radius: 5px;
		background: rgba(255, 255, 255, 0.95);
		overflow: hidden;
		.yindao_wrap {
			display: flex;
			justify-content: center;
			align-items: center;
			min-height: 100px;
		}
	}
	
	.ms-content {
		padding: 30px 30px;
	}
	
	.login-btn {
		text-align: center;
	}
	
	.login-btn button {
		width: 100%;
		height: 36px;
		margin-bottom: 10px;
	}
	
	.login-tips {
		font-size: 12px;
		line-height: 30px;
		color: #fff;
	}
</style>